package cc.eevee.jni.libdynamic;

import android.util.Log;

public class Bird {

  private final long mNativeRef;

  public Bird(String name) {
    mNativeRef = nativeCreate(name);
  }

  public String greeting() {
    return nativeGreeting(mNativeRef);
  }

  @Override
  protected void finalize() throws Throwable {
    nativeDestroy(mNativeRef);
    super.finalize();
  }

  private native long nativeCreate(String name);
  private native void nativeDestroy(long nativeRef);

  private native String nativeGreeting(long nativeRef);

  static {
    try {
      System.loadLibrary("bird");
    } catch (Exception e) {
      Log.e(Bird.class.getSimpleName(), "load native library failed");
      e.printStackTrace();
    }
  }
}
